#!/bin/bash

# rsync到特定的端口
port=2222

function usage() {
    echo "$( basename $0 ) [-p <port>] <src> <dst>"
    echo "    rsync到特定的ssh端口"
    echo "    参数:"
    echo "    -p <port>: 端口号，缺省为2222"

    exit 1
}

# 分析参数
shiftCnt=0

while getopts ":p:" arg
do
    case "${arg}" in
        p)
            port=${OPTARG}
            shiftCnt=$(( ${shiftCnt} + 2 ))
            ;;
        *)
            usage
            ;;
    esac
done

# shift掉已经分析的参数
shift ${shiftCnt}
src=$1
dst=$2

if [ -z "${src}" -o -z "${dst}" ]
then
    usage
fi

echo rsync -av -e "'ssh -p ${port}'" "${src}" "${dst}"
rsync -av -e "ssh -p ${port}" "${src}" "${dst}"
